<?php

class Date
{
    static public function notDate($d,$m,$y,$msg)
    {
        $dayOfMonth=array(31,28,31,30,31,31,30,31,30,31,30,31);
        if ( ($d==0) ||
            ($m==2 && $y%4==0 && $d>29) || // There is 29 days in February of Leap-year
            (($m!=2 || $y%4!=0) && $d>$dayOfMonth[$m-1]) ) {
            echo "$msg (d/m/y) '$d/$m/$y' " . fl('err_date') . "<br>";
            return true;
        }
        return false;
    }

    /**
     * Get UNIX timestamp by timezone offset
     * @param integer $hoursOffset
     * @param integer $timestamp
     * @return integer timestamp
     */
    static public function getGmtTime($hoursOffset = 0, $timestamp = null)
    {
        if (null === $timestamp) {
            $timestamp = time();
        }

        $gmtTimestamp = strtotime(gmdate('Y-m-d H:i:s', $timestamp));

        if (0 === $hoursOffset) {
            return $gmtTimestamp;
        }

        return $gmtTimestamp + $hoursOffset*3600;
    }

    static public function toLocalTime($time, $offset = 0)
    {
        return $time + $offset*3600;
    }
}
